package com.ikonke.iot.alarm.config;

import com.ikonke.iot.alarm.influxdb.InfluxDbConnector;
import org.influxdb.InfluxDB;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: liull
 * @Description: InfluxDB单例
 * @Date: Created in 16:56 2020/5/13
 * @Modified By:
 */
@Configuration
@ConditionalOnProperty(prefix = "influx", name = "url")
public class InfluxDbConfig {

    @Autowired
    private InfluxProperties influxProperties;

    @Bean
    public InfluxDB influxDB() {
        return InfluxDbConnector.connectToInfluxDB(influxProperties.getUrl(), InfluxDB.ResponseFormat.JSON, influxProperties.getUser(),
                influxProperties.getPassword());
    }
}
